package com.doctor.ui.office;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.R.anim;
import android.R.integer;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.doctor.adapter.CalendarAdapter;
import com.doctor.adapter.MyPagerAdapter;
import com.doctor.adapter.MyPagerAdapter.MyPagerAdapterCallback;
import com.doctor.ui.BaseFragment;
import com.doctor.ui.R;

public class WorkArrangeFrag extends BaseFragment implements MyPagerAdapterCallback{

	/**
	 * 上班安排
	 */
	
	private Context context;
	private TextView yearAndMonth;
	
	private ViewPager viewPager;
	private static final int initiaPosition=10002;
	private Calendar calendar;
	private MyPagerAdapter pagerAdapter;
	private WorkArrangeCallback callback;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		context=getActivity();
		View view=inflater.inflate(R.layout.work_arrange, container, false);
		initiaView(view);
		callback.onWorkArrange();
		return view;
	}
	
	@Override
	public void onDestroyView() {
		// TODO Auto-generated method stub
		super.onDestroyView();
		context=null;
		yearAndMonth=null;
		viewPager=null;
		calendar=null;
		pagerAdapter=null;
	}
	
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		try {
			callback=(WorkArrangeCallback) activity;
		} catch (ClassCastException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void onDetach() {
		// TODO Auto-generated method stub
		super.onDetach();
		callback=null;
	}
	
	//初始化控件
	@Override
	protected void initiaView(View view) {
		// TODO Auto-generated method stub
		calendar=Calendar.getInstance();
		yearAndMonth=(TextView) view.findViewById(R.id.yearMonth);
		yearAndMonth.setText(calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+"月");
		
		viewPager=(ViewPager) view.findViewById(R.id.viewPager);
		pagerAdapter=new MyPagerAdapter(context,WorkArrangeFrag.this);	
		viewPager.setAdapter(pagerAdapter);		
		//设置第10002屏为当前屏，才能实现向左循环
		viewPager.setCurrentItem(initiaPosition);
	}

	//设置标题年月
	@Override
	public void onSetYearAndMonth(String str) {
		// TODO Auto-generated method stub
		yearAndMonth.setText(str);
	}
	
	public interface WorkArrangeCallback{
		public void onWorkArrange();
	}
	
	
}
